package com.example.springsecurity.service.base;

import com.google.common.collect.Sets;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.util.Map;
import java.util.Set;

/**
 * @Description：
 * @Author： fengcheng
 * @Date： 2025/1/20 17:31
 */
@Slf4j
@Service
public class BaseCommonService {

    public Set<String> sysReqPath = Sets.newConcurrentHashSet();

    @Resource
    @Lazy
    private RequestMappingHandlerMapping requestMappingHandlerMapping;

    /**
     * @Description：获取系统中所有Controller中的请求地址
     * @Author：fengcheng
     * @Date：2025/1/20 18:16
     * @Return：void
     */
    public void getAllRequestPath() {
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
        for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()) {
            RequestMappingInfo requestMappingInfo = entry.getKey();
            Set<String> directPaths = requestMappingInfo.getPathPatternsCondition().getDirectPaths();
            sysReqPath.addAll(directPaths);
        }
    }
}
